// 适配
document.documentElement.style.fontSize = innerWidth / 7.5 + 'px';
window.onresize = function () {
	document.documentElement.style.fontSize = innerWidth / 7.5 + 'px';
}

var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?9b582f019242860de267edc341ee0bfa";
  var s = document.getElementsByTagName("script")[0];
  s.parentNode.insertBefore(hm, s);
})();

// 页面可滚动
window.onload = function () {
	mui('.mui-scroll-wrapper').scroll({
		deceleration: 0.003, //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
		bounce: false, //滚动条是否有弹力默认是true
	});

	setInterval(function () {
		var side = $("#offCanvasSide").css("transform").split(',')[4];
		if (side > 200) {
			$(".pc_icon").css("display", "block")
		} else {
			$(".pc_icon").css("display", "none")
		}
	}, 50)
	// 赔偿预估
	$(".pc_icon").on("tap", () => {
		show($(".pc_box"));
	})
	// 立即咨询
	$(".btn").on("tap", () => {
		show($(".ljzx_box"));
	})
	// 微信咨询
	$(".wx_btn").on("tap", () => {
		show($(".wx_box"));
	})
	// 取消
	$(".qx").on("tap", () => {
		close();
	})
	// 复制


	$(".tel").on("tap", () => {
		token(2);
		window.location.href = "tel:18171100301";
	})
	$(".lawyer_tel_qx").on("tap", () => {
		$(".lawyer_tel_box").css("display", "none");
	})
	// 页面跳转
	$(".nav_home").on("tap", () => {
		window.location.href = "http://yh.cn/mobile/index/index.html";
	})
	$(".nav_computer").on("tap", () => {
		window.location.href = "http://yh.cn/mobile/index/computer.html";
	})
	$(".nav_anli").on("tap", () => {
		window.location.href = "http://yh.cn/mobile/index/anli.html";
	})
	$(".nav_team").on("tap", () => {
		window.location.href = "http://yh.cn/mobile/index/team.html";
	})
	$(".nav_mine").on("tap", () => {
		window.location.href = "http://yh.cn/mobile/index/mine.html";
	})
	// 电话查询 
	$(".zx_btn").on("tap", () => {
		$(".zx_btn").attr("disabled", true);
		let name = $("#name").val();
		let phone = $("#tel").val();
		let domain = document.URL;
		if (name != "" && (/^1[3456789]\d{9}$/.test(phone))) {
			$.post("http://yh.cn/api/index/mobile_lands", { nick: name, phone: phone, url: domain }, function (data) {
				if (data == 1) {
					mui.alert('恭喜您，预约成功！', '提示', function () {
						window.location.reload();
					})
				} else {
					mui.alert('系统错误,请联系管理员或刷新页面!', '提示', function () {
						window.location.reload();
					})
				}
			}, "json")
		} else {
			$(".zx_btn").attr("disabled", false);
			mui.alert('请检查输入信息！', '提示', function () {
				if (!(/^1[3456789]\d{9}$/.test(phone))) {
					$("#tel").css("border-color", "red");

				}
				if (name == "") {
					$("#name").css("border-color", "red");

				}
			});
		}
	})

	$("#name").keydown(function () {
		$("#name").css("border-color", "rgba(0,0,0,.2)");
	})
	$("#tel").keydown(function () {
		$("#tel").css("border-color", "rgba(0,0,0,.2)");
	})

	//隐藏咨询按钮
	$("input").focus(function () {
		$(".btn_box").css("display", "none");
	})
	$("input").blur(function () {
		$(".btn_box").css("display", "block");
	})

	document.body.addEventListener('touchmove', function (e) {
		if (document.activeElement)
			document.activeElement.blur();
	}, { passive: false });

	//复制
	var clipboard = new Clipboard('.wx_fz');
	clipboard.on('success', function (e) {

	});
	clipboard.on('error', function (e) {
		console.log(e);
	});
	$(".wx_fz").on("tap", function () {
		mui.alert('复制成功！', '提示', function () {
			token(1);
			window.location.href = "weixin://";
		})
	})
	if (window.orientation == 90 || window.orientation == -90) {
		$("body").css("position", "fixed");
		$(".pd").css("display", "block");
	} else {
		$("body").css("position", "block");
		$(".pd").css("display", "none");
	}
}



function show(tag) {
	$(".pc_bg").css("display", "block");
	tag.css("display", "block");
}

function close() {
	$(".pc_bg").css("display", "none");
	$(".pc_box").css("display", "none");
	$(".ljzx_box").css("display", "none");
	$(".wx_box").css("display", "none");
}

function token(e) {
        var url = document.URL;
        var address = '武汉';
        $.post("http://yh.cn/lands/index/statistics",{type:e,url:url,address:address},function (data) {},"json");
    }

//设备跳转
!(function () {
	function browserRedirect() {
		var sUserAgent = navigator.userAgent.toLowerCase();
		var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
		var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
		var bIsMidp = sUserAgent.match(/midp/i) == "midp";
		var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
		var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
		var bIsAndroid = sUserAgent.match(/android/i) == "android";
		var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
		var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
		if (!bIsIpad && !bIsIphoneOs && !bIsMidp && !bIsUc7 && !bIsUc && !bIsAndroid && !bIsCE && !bIsWM) {
			window.location.href = "http://yh.cn"
		}
	}

	browserRedirect();

	//检测是否横屏操作
	window.onorientationchange = function () {
		if (window.orientation == 90 || window.orientation == -90) {
			$("body").css("position", "fixed");
			$(".pd").css("display", "block");
		} else {
			$("body").css("position", "block");
			$(".pd").css("display", "none");
		}
	}
})();

$(function () {
	var pd = `<div class="pd">
				<div class="pd_box">
					<img class="pd_img" src="http://yh.cn/themes/simpleboot3/public/assets/simpleboot3/mobile/img/pd.png" />
					<p>为了您的良好体验</p>
					<p>请将手机/平板竖屏操作</p>
				</div>		
			<div>`;

	$("body").append(pd);
})
